<?xml version="1.0" encoding="UTF-8" ?>
<%@ page import="org.swimv2.model.Persona" %>
<%@ page import="java.util.Collection" %>
<%@page import="landmark.LandmarkUtente"%>
<%@page import="landmark.Link"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<script language="javascript">
function addInput(divName){
 	
	  var newdiv = document.createElement('div');
      newdiv.innerHTML = "<br>nuova abilità: " + "&nbsp; <input type='text' name='abSupp'>" + "<div id='button'><input type='button' name='eliAb' id='submit' value='elimina' onclick='deleteNewElement(this)'/></div>";
	  document.getElementById(divName).appendChild(newdiv);
   
}

function deleteNewElement(n){
	n.parentNode.parentNode.parentNode.removeChild(n.parentNode.parentNode);
}
</script>
<script type="text/javascript">
    function validateDisp(){
        x=document.getElementById("disp");
        num=x.myInput.value;
        if (num>=0 && num<=100) {
            return true;
        }else{
            alert("Must be between 0 and 100");
            return false;
        }
}
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js"></script> 
	<!-- jquery validazioni //--> 
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.js"></script> 
<script type="text/javascript" src="validation_reg.js"></script>


<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Modifica profilo</title>
<link rel="stylesheet" type="text/css" href="scheletro.css">
</head>
<body>

<div id="container">
	<table class="topHome">
		<tr>
			    <td id="logoHome">
		<a href="home.jsp">Swim v2</a>
		<br><br><b> A help with a click!</b>
	
			    </td>
				<td class="personal">
			
					<b>Ciao :<a href="PaginaProfiloServlet">${sessionScope.utente.nome}</a> </b>&nbsp;&nbsp;&nbsp;<a href="Notifiche"><b>Interazioni</b></a>&nbsp;<a href="messaggi.jsp"><b>Messaggi</b></a>&nbsp;&nbsp;&nbsp;<div id="button"><a href="Logout" id="logout">Logout</a></div>
	
				</td>		
		</tr>
	</table>

<%String messaggio = (String) request.getAttribute("messaggio");
	if(messaggio != null) {
				out.println("<p class='errorMessage'>" + messaggio + "</p>");
		} %>


<div id="nav"> 
	<ul>
		<%
			Link a[]  = LandmarkUtente.getLandmark();
			for(int i=0; i<a.length; i++)
			{
		%>
			<%
				if(a[i].getValue().equalsIgnoreCase("Modifica Profilo"))
				{
			%>
				<li><a href="<%=a[i].getHref() %>"><u><%=a[i].getValue() %></u></a></li>
			<%	}
			%>
			
			<%	if(!a[i].getValue().equalsIgnoreCase("Modifica Profilo"))
				{
			%>
				<li><a href="<%=a[i].getHref() %>"><%=a[i].getValue() %></a></li>
			<%} 
			%>
		<%} 
		%>
	</ul>
</div>

<% Persona u = (Persona) request.getSession().getAttribute("utente"); %>
<div id="form">
	<form action="ModificaProfilo" method="post" id="form_register" enctype="multipart/form-data">
   
    <fieldset>
        <legend>Modifica il tuo profilo</legend>
        
        
        	<br><br>
                <label for="nome">Nome</label>
                <input type="text" name="nome" id="nome" value="<%=u.getNome() %>"/> <br><br>
                
        		<label for="cognome">Cognome</label>
                <input type="text" name="cognome" id="cognome" value="<%=u.getCognome() %>"/><br><br>
                
          		 <label for="titolo">Regione d'Italia</label>
                <select name="regione" id="regione" >
                	<option value="<%=u.getRegione() %>"><%=u.getRegione() %></option>
                	<option value="">-All-</option>
                	<option value="Abruzzo">Abruzzo</option>
                	<option value="Basilicata">Basilicata</option>
                	<option value="Calabria">Calabria</option>
                	<option value="Campania">Campania</option>
                	<option value="Emilia Romagna">Emilia Romagna</option>
                	<option value="Friuli-Venezia-Giulia">Friuli-Venezia-Giulia</option>
                	<option value="Lazio">Lazio</option>
                	<option value="Liguria">Liguria</option>
                	<option value="Lombardia">Lombardia</option>
                	<option value="Marche">Marche</option>
                	<option value="Molise">Molise</option>
                	<option value="Piemonte">Piemonte</option>
                	<option value="Puglia">Puglia</option>
                	<option value="Sardegna">Sardegna</option>
                	<option value="Sicilia">Sicilia</option>
                	<option value="Toscana">Toscana</option>
                	<option value="Trentino Alto-Adige">Trentino Alto-Adige</option>
                	<option value="Umbria">Umbria</option>
                	<option value="Valle d'Aosta">Valle d'Aosta</option>
                	<option value="Veneto">Veneto</option>
                </select> <br><br>
          
          		<label >Disponibilità</label>
                
                <input type="text" name="disp" id="disp" value="<%=String.valueOf(u.getDisponibilita())%>"></input><br><br>
                	
                <label for="foto">Modifica foto:</label>
               <input type="file" name="inputFoto" id="inputFoto" accept="image/jpeg"/><br><br>
        	   
        	   <br><br>
        	   <fieldset>
   					             
                    <legend>Abilità</legend>
					<%
					@SuppressWarnings("unchecked")
					Collection<String> abUtente= (Collection<String>) request.getAttribute("abUtente");	
					@SuppressWarnings("unchecked")
					Collection<String> listAb= (Collection<String>) request.getAttribute("listAb");		
					if(abUtente.size()>0) {
						%>
					<ul>
					<%
						for(String s: abUtente) {
							
						%>
	                  <li>
		                    <label for="ab"><% out.print(s);%>&nbsp;</label>
		                    <input type="checkbox" name="ab" id="ab" value="<% out.print(s);%>" checked="checked"/><br>
					  </li>
                	<%
							
						}
						%>
						</ul>
					<% }%>
					<%
					if(listAb.size()>0) {
						%>
					<ul>
					<%
						for(String ab: listAb) {
							
						%>
	                  <li> 
		                    <label for="ab2"><% out.print(ab);%>&nbsp;</label>
		                    <input type="checkbox" name="ab2" id="ab2" value="<% out.print(ab);%>"/><br>
						</li>
                	<%
							
						}
						%>
						</ul>
					<% }%>
                </fieldset><br><br>
        	   <div id="addAb">
                <b>Abilità aggiuntive:</b> <br><br>
                Vuoi aggiungere altre abilità? :
                
                <div id="button"><input type="button" name="addAb" id="submit" value="+" onclick="addInput('addAb');"/></div> <br><br>
            	
				</div> 
				
		        <br><br><br><br>	
                <div id="button"><input type="submit" name="submit" id="submit" value="Modifica" /></div>
            
        
  	</fieldset>   

	</form>
</div>

</div>
</body>
</html>